﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace WebService
{
    public class KhachHangDAO
    {
        public Tour[] TimTour(string tour)
        {
            Tour[] DSTour;
            string query = "select MaTour from TourDuLich T where T.TenTour like N'%" + tour + "%' or (select TenDD from DiaDiem where TenDD like N'%" + tour + "%' and MaDD like T.MaDiaDiemBD) is NOT NULL or (select TenDD from DiaDiem where TenDD like N'%" + tour + "%' and MaDD like T.MaDiaDiemKT) is NOT NULL";

            DataTable dt = DataProvider.excecuteQuery(query);
            int n = dt.Rows.Count;
            
            DSTour = new Tour[n];
            for (int i = 0; i < n; i++)
            {
                String MaTour;
                MaTour = dt.Rows[i]["MaTour"].ToString();
                DSTour[i] = new Tour();
                DSTour[i].LayThongTin(MaTour);
            }
            return DSTour;
        }
        public Tour[] XemLS(String MaKH)
        {
            Tour[] DSTour;
            string query = "select distinct MaTour from DatTour where MaKH like '" + MaKH+"'";
            DataTable dt = DataProvider.excecuteQuery(query);
            int n = dt.Rows.Count;
            String MaTour;
            DSTour = new Tour[n];
            for (int i = 0; i < n; i++)
            { 
                MaTour = dt.Rows[i]["MaTour"].ToString();
                DSTour[i] = new Tour();
                DSTour[i].LayThongTin(MaTour);
            }
            return DSTour;
        }
        public bool DatTour(String MaTour, String MaKH)
        {
            string query = "insert into DatTour(MaKH,MaTour) values('"+MaKH+"','"+MaTour+"')";
            DataProvider.excecuteQuery(query);
            return true;
        }
        public bool AMuaTour(String MaTour, int SoNguoi, String[] ListNguoiDi)
        {
            String insert = "insert into DatTour values('"+MaTour+"','Agent1',"+SoNguoi+")";
            DataProvider.excecuteQuery(insert);
            return true;
        }
    }
}